package com.gs.weather.controller;

import com.gs.weather.entity.DisasterSubtype;
import com.gs.weather.entity.DisasterSubtypeStrength;
import com.gs.weather.entity.DisasterType;
import com.gs.weather.service.DisasterSubtypeService;
import com.gs.weather.service.DisasterSubtypeStrengthService;
import com.gs.weather.service.DisasterTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/27 0027
 */
@Controller
@RequestMapping(value = "type")
public class DisasterTypeController {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    DisasterTypeService typeService;
    @Autowired
    DisasterSubtypeService subtypeService;
    @Autowired
    DisasterSubtypeStrengthService strengthService;

    //添加灾害类型
    @RequestMapping(value = "addType")
    public void addType(DisasterType type) {
        typeService.addDisasterType(type);
    }

    //更新灾害类型
    @RequestMapping(value = "updateType")
    public void updateType(DisasterType type) {
        typeService.updateDisasterType(type);
    }

    /*手动分页*/
    //获取灾害类型
    @RequestMapping(value = "getType")
    @ResponseBody
    public List<DisasterType> getType(Integer pageNum) {
        return typeService.getAllDisasterType(pageNum);
    }

    //删除灾害类型
    @RequestMapping(value = "deleteType")
    public void deleteType(int id) {
        typeService.deleteDisasterType(id);
    }

    //添加灾害子类型
    @RequestMapping(value = "addSubtype")
    public void addSubtype(DisasterSubtype subtype) {
        subtypeService.addSubtype(subtype);
    }

    //更新灾害子类型
    @RequestMapping(value = "updateSubtype")
    public void updateSubtype(DisasterSubtype subtype) {
        subtypeService.updateSubtype(subtype);
    }

    //获取灾害类型的子类型
    @RequestMapping(value = "getSubtypeByTypeId")
    @ResponseBody
    public List<DisasterSubtype> getSubtypeByTypeId(int id) {
        return subtypeService.getSubtypeByTypeId(id);
    }

    //删除子类型
    @RequestMapping(value = "deleteSubtype")
    public void deleteSubtype(int id) {
        subtypeService.deleteSubtype(id);
    }

    //添加灾害强度
    @RequestMapping(value = "addStrength")
    public void addStrength(DisasterSubtypeStrength subtypeStrength) {
        strengthService.addStrength(subtypeStrength);
    }

    //更新灾害强度
    @RequestMapping(value = "updateStrength")
    public void updateStrength(DisasterSubtypeStrength subtypeStrength) {
        strengthService.updateStrength(subtypeStrength);
    }

    //删除强度
    @RequestMapping(value = "deleteStrength")
    public void deleteStrength(int id){
        strengthService.deleteStrength(id);
    }

}
